//
//  SuicateViewController.m
//  On The Load
//
//  Created by 我爱的妞 on 15/11/5.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "SuitcaseViewController.h"
#import "HXLSuitcaseView.h"
#import "HXLWeatherViewController.h"
#import "HXLTravelGuidesViewController.h"
#import "HXLTravelPlansViewController.h"
#import "HXLTravelBookViewController.h"
#import "HXLExchangeRateViewController.h"
#import "HXLTravelRescueViewController.h"
#import "CoreDataManager.h"
#import "TravelPlan.h"
#import <MJRefresh.h>
#import "HXLMapViewController.h"


@interface SuitcaseViewController ()<pushNextViewDelegate>
@property (nonatomic, strong) NSArray *controllerArray;
@property (nonatomic, strong) HXLWeatherViewController *weatherVC;
@property (nonatomic, strong) HXLTravelGuidesViewController *guidesVC;
@property (nonatomic, strong) HXLTravelPlansViewController *planVC;
@property (nonatomic, strong) HXLTravelBookViewController *bookVC;
@property (nonatomic, strong) HXLExchangeRateViewController *rateVC;
@property (nonatomic, strong) HXLTravelRescueViewController *rescueVC;

@property (nonatomic, strong) CoreDataManager *coreDataManager;
@property (nonatomic, strong) NSMutableArray *allArray;


@end

@implementation SuitcaseViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.allArray = [NSMutableArray array];

    self.coreDataManager = [CoreDataManager shareManager];
    
    
    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"TravelPlan"];
    NSArray *resultArray = [self.coreDataManager.managedObjectContext executeFetchRequest:request error:nil];
    
    for (TravelPlan *model in resultArray) {
        NSLog(@"ttt%@lll%@", model.cityName, model.cityNameEn);
        [self.allArray addObject:model];
    }

    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.translucent = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"旅行箱";
    HXLSuitcaseView *suitcaseView = [[HXLSuitcaseView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:suitcaseView];

    suitcaseView.myDelegate = self;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"map-@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(mapAction:)];
    
}

- (void) mapAction:(UIBarButtonItem *) bar {
    HXLMapViewController *mapVC = [[HXLMapViewController alloc] init];
    mapVC.placeArray = self.allArray;
    NSLog(@"map = %@",self.allArray);
    [self.navigationController pushViewController:mapVC animated:YES];
    
}

//push到二级页面
- (void)pushNextViewController:(NSInteger)tag {
    
    
    HXLWeatherViewController *weatherVC = [[HXLWeatherViewController alloc] init];
    HXLTravelGuidesViewController  *guidesVC = [[HXLTravelGuidesViewController alloc] init];
    

    HXLTravelPlansViewController *planVC = [[HXLTravelPlansViewController alloc] init];
//    HXLTravelBookViewController *bookVC  = [[HXLTravelBookViewController alloc] init];
    HXLExchangeRateViewController *rateVC = [[HXLExchangeRateViewController alloc] init];
//    HXLTravelRescueViewController *rescueVC = [[HXLTravelRescueViewController alloc] init];

//        self.controllerArray = @[planVC,weatherVC, guidesVC,rateVC, bookVC, rescueVC];

    
    if (tag == 1000) {
        [self.navigationController pushViewController:planVC animated:YES];
    }if (tag == 1001) {
        NSLog(@"weather = %@",self.allArray);
        weatherVC.cityArray = self.allArray;
        
        [self.navigationController pushViewController:weatherVC animated:YES];
    }if (tag == 1002) {
        guidesVC.countryIdArray = self.allArray;
       
        [self.navigationController pushViewController:rateVC animated:YES];

        
    }if (tag == 1003) {
        [self.navigationController pushViewController:guidesVC animated:YES];

    }
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
